<?
require_once("../config/dbconn.php");require_once("../config/powercls.php");

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" src="../class/ajax.js" type="text/javascript"></script>
<script language="javascript" src="../class/js.js" type="text/javascript"></script>
<script language="javascript">
function gxtex(hyid,depth){
	var dobj=document.getElementById("d_"+hyid);
	var imgobj=document.getElementById("img_"+hyid);
	if (dobj.style.display=="block"){
		dobj.style.display="none";
		if (imgobj.src="treeimgs/tree_minus.gif") imgobj.src="treeimgs/tree_plus.gif";else imgobj.src="treeimgs/tree_minus.gif";
	}else{
		dobj.style.display="block";
		if (imgobj.src="treeimgs/tree_minus.gif") imgobj.src="treeimgs/tree_minusl.gif";else imgobj.src="treeimgs/tree_minus.gif";
		dobj.innerHTML="载入中.........";
	}
	////利用ajax动态的读取该用户的推荐下级
	var xmlHttp=getXMLRequester();
	var url="ajax_glnet.php";	
	url=url+"?hyid="+hyid+"&dpth="+depth;
	url=url+"&timeStamp="+new Date().getMilliseconds();
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4 && xmlHttp.status==200){ 
			dobj.innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null);
}
</script>

<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	
}
td{
	font-size:12px;
}
-->
</style>

<link href="images/skin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" height="29" valign="top" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
    <td width="935" height="29" valign="top" background="images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
      <tr>
        <td height="31"><div class="titlebt">管理网体</div></td>
      </tr>
    </table></td>
    <td width="16" valign="top" background="images/mail_rightbg.gif"><img src="images/nav-right-bg.gif" width="16" height="29" /></td>
  </tr>
  <tr>
    <td height="71" valign="middle" background="images/mail_leftbg.gif">&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9">
	
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td valign="top">
		<!------------------------>
		<form action="?action=query" method="post" name="form1">
	&nbsp;&nbsp;&nbsp;用户编号:&nbsp;&nbsp;
	<input name="username" type="text" size="10" />
	<input name="b2" type="submit" value="查询" ></form> 
  <?
  //获取公司的第一个人
  $sqlgs="select * from {$db_prefix}users where ifnull(tjuser,0)=0 and ifnull(gluser,0)=''";
  $rsgs=$db->get_one($sqlgs);
  $gsuser=$rsgs['username'];
  //获取顶层用户
  if ($action=="query"){
	 if(trim($username)==""){
		$sql1="select * from {$db_prefix}users where username='".$gsuser."'";
	}else{
		$sql1="select * from {$db_prefix}users where username='".trim($username)."'";
	}
 }else{
 	$sql1="select * from {$db_prefix}users where username='".$gsuser."'";
 }
 
  $rs1=$db->get_one($sql1);
  if (empty($rs1["id"])) die("<center>用户不存在</center>");
  
  ?>
  <div style="margin-left:50px;"><img border=0  src="treeimgs/tree_diropen.gif" width="16" height="16" /><? echo $rs1["username"]?>  [<? echo $hyrankary[$rs1["rank"]]?>] [注册日期:<? echo date("Y-m-d",$rs1["regtime"])?>]</div>
  <?
  //获取第一代
  $sql="select * from {$db_prefix}users where gluser='".$rs1["username"]."'";
 
  $result=$db->query($sql);$rstulnum=$db->num_rows($result);$i=0;
  while ($rs=$db->fetch_array($result)){
  	$i++;
  ?>
  <div style="margin-left:50px;"><? $chdbit=getchild($rs["username"]);
	if ($chdbit){
		echo '<a href="#img_'.$rs["id"].'" onclick="gxtex('.$rs["id"].',1);">';
		echo ($i==$rstulnum)?'<img border=0 id="img_'.$rs["id"].'"  src="treeimgs/tree_plusl.gif" />':'<img border=0 id="img_'.$rs["id"].'"  src="treeimgs/tree_plus.gif"  />';
		echo "</a>";
	}else{
		echo ($i==$rstulnum)?'<img border=0 id="img_'.$rs["id"].'"  src="treeimgs/tree_blankl.gif" />':'<img border=0 id="img_'.$rs["id"].'"  src="treeimgs/tree_blank.gif"  />';
	}
	
	?><? echo $rs["username"]?> [第2层] [<? echo $hyrankary[$rs["rank"]]?>] [注册日期:<? echo date("Y-m-d",$rs["regtime"])?>]</div>
  <div id="d_<? echo $rs["id"]?>" style="margin-left:50px;display:none"></div>
  <?
  }
  $db->free_result($result);
  ?>

<?
//////////////函数/////////////////////
function getchild($hyname){
	global $db,$db_prefix;
	$sql_chd="select id from {$db_prefix}users where gluser='".$hyname."' limit 1";
	$rs_chd=$db->get_one($sql_chd);
	if (!empty($rs_chd["id"])) return true;else return false;
}
?>
		<!------------------------>
		</td>
      </tr>
    </table>
	<p>&nbsp;</p>
	<p>&nbsp;</p>
	<p>&nbsp;</p>
	<p>&nbsp;</p></td>
    <td background="images/mail_rightbg.gif">&nbsp;</td>
  </tr>
  <tr>
    <td valign="middle" background="images/mail_leftbg.gif"><img src="images/buttom_left2.gif" width="17" height="17" /></td>
      <td height="17" valign="top" background="images/buttom_bgs.gif">&nbsp;</td>
      <td background="images/mail_rightbg.gif"><img src="images/buttom_right2.gif" width="16" height="17" /></td>
  </tr>
</table>

</body>
</html>